using System;
using System.Collections.Generic;

namespace ColladaDotNet.OpenTKMapping
{
	public class Sampler2D: DocumentLibraryElement<fx_sampler2D_common>
	{
		public string Source
		{
			get
			{
				return Collada.source;
			}
		}
	}

	public class NewParam : DocumentLibraryElement<common_newparam_type>
	{
		internal override void Load(common_newparam_type colladaData)
		{
			base.Load(colladaData);

			item = Document.CreateElement(colladaData.Item);
		}

		private object item;
		public ItemChoiceType2 Type
		{
			get
			{
				return Collada.ItemElementName;
			}
		}
		public Sampler2D Sampler2D
		{
			get
			{
				if (Collada.ItemElementName == ItemChoiceType2.sampler2D)
				{
					return (Sampler2D)item;
				}
				return null;
			}
		}

		public double Float
		{
			get
			{
				if (Collada.ItemElementName == ItemChoiceType2.@float)
				{
					return Convert.ToDouble(item);
				}
				return 0.0;
			}
		}

	

		public Surface Surface
		{
			get
			{
				if (Collada.ItemElementName == ItemChoiceType2.surface)
				{
					return (Surface)item;
				}
				return null;
			}
		}
	}
	public class EffectCommonProfile:EffectProfile
	{
		private EffectCommonTechnique tech;
		List<NewParam> newParams = new List<NewParam>();

		public override void Load(ColladaXmlNode colladaData)
		{
			base.Load(colladaData);
			if (Collada.Items != null)
			foreach (var item in Collada.Items)
			{
				if (item.GetType() == typeof(common_newparam_type))
				{
					newParams.Add(Document.CreateElement<NewParam>(item));
				}
			}
			tech = Document.CreateElement<EffectCommonTechnique>(Collada.technique);
		}

		public effectFx_profile_abstractProfile_COMMON Collada
		{
			get
			{
				return (effectFx_profile_abstractProfile_COMMON)rawNode;
			}
		}

		public override void Bind()
		{
			base.Bind();
			tech.Bind(this);
		}

		public override void Unbind()
		{
			base.Unbind();
			tech.Unbind(this);
		}

		public NewParam GetNewParam(string texture)
		{
			foreach (var newParam in newParams)
			{
				if (newParam.Sid == texture)
					return newParam;
			}
			return null;
		}

	}
}